# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=procps
pkgver=3.3.17
pkgrel=1
pkgdesc="Utilities for monitoring your system and processes on your system"
url="https://gitlab.com/procps-ng/procps"
arch="all"
license="GPL-2.0-or-later AND LGPL-2.1-or-later"
makedepends="ncurses-dev gettext-dev autoconf automake libtool"
checkdepends="dejagnu"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang libproc"
source="https://gitlab.com/procps-ng/procps/-/archive/v$pkgver/procps-v$pkgver.tar.gz
	musl-fixes.patch
	"
builddir="$srcdir/$pkgname-v$pkgver"

prepare() {
	# NOTE: Name of the tarball's top-level directory contains SHA1.
	ln -fs $srcdir/$pkgname-v$pkgver-* "$builddir"

	default_prepare

	# force misc/git-version-gen use the correct version (instead of UNKNOWN);
	# however only do it if the upstream tarball really misses it.
	if test ! -f .tarball_version ; then
		rm -f .version
		echo "$pkgver" > .tarball-version
	fi
	./autogen.sh
}

build() {
	export LIBS="$LIBS -lintl"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/ \
		--bindir=/bin \
		--sbindir=/sbin \
		--libdir=/lib \
		--mandir=/usr/share/man \
		--sysconfdir=/etc \
		--docdir=/usr/share/doc/procps \
		--datarootdir=/usr/share \
		--disable-static \
		--disable-w-from \
		--disable-kill \
		--disable-rpath \
		--with-ncurses
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" ldconfig=true install="install -D" \
		install

	# These binaries are identical.
	ln -sf pgrep "$pkgdir"/bin/pkill

	# Override BusyBox symlinks
	mkdir -p "$pkgdir"/usr/bin
	for i in free pgrep pkill pmap pwdx top uptime; do
		mv "$pkgdir"/bin/$i "$pkgdir"/usr/bin/$i
	done

	install -d "$pkgdir"/usr/lib
	mv "$pkgdir"/include "$pkgdir"/usr/ \
		&& mv "$pkgdir"/lib/pkgconfig "$pkgdir"/usr/lib/
}

libproc() {
	pkgdesc="Library for monitoring system and processes"

	install -d "$subpkgdir"/
	mv "$pkgdir"/lib "$subpkgdir"/
}

sha512sums="
070076cf6bbbd8b6b342af361035f11d9c7381c5d1e2e430a5f2584ff55656254e8f863a40ca75a38870a5007d1b22a0d452bef13fa0ab89e4bf9676826fd788  procps-v3.3.17.tar.gz
54975d8fd87ff39551a04fb9f7ff6ffcec6fa2f7933a59c3f3d2b927cc0a21263259e864a9775a96f0996511f249fa72c1975010098fe12cff22202cdde1ed87  musl-fixes.patch
"
